package gg.com.toolbox.adapter;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.HashMap;

import gg.com.toolbox.R;

/**
 * 首页功能适配器
 * Created by gaoge on 2017/10/10.
 */

public class FunctionAdapter extends BaseAdapter {
    private LayoutInflater lf = null;
    private ArrayList<HashMap<String, String>> list = null;
    private Activity activity = null;

    public FunctionAdapter(Activity activity, ArrayList<HashMap<String, String>> list) {
        lf = LayoutInflater.from(activity);
        this.activity = activity;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @SuppressLint("InflateParams")
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = lf.inflate(R.layout.function_gridview, null);
            holder = new ViewHolder();
            holder.textview= (TextView) convertView.findViewById(R.id.textview);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.textview.setText(list.get(position).get("name"));
        return convertView;
    }

    private class ViewHolder {
      private TextView textview=null;
    }
}
